package com.guli.sms.utils;
/*
 * @Author 罗俊
 * @date 2020/11/30 - 2:07 下午
 *
 */

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {
    /**
     * 获取今天 00:00:00 的日期
     * @return
     */
    public static Date getTodayZeroHourZeroMinuteZeroSecond() {

        Calendar instance = Calendar.getInstance();

        instance.set(Calendar.HOUR_OF_DAY, 0);

        instance.set(Calendar.MINUTE, 0);

        instance.set(Calendar.SECOND, 0);
        // 得到今天
        return new Date(instance.getTimeInMillis());

        /*LocalDate now = LocalDate.now();

        LocalTime min = LocalTime.MIN;

        LocalDateTime dateTime = LocalDateTime.of(now, min);*/

    }

    /**
     * 获取该日期几天之后的新日期（从传入日期的 00:00:00开始计算）
     * @param instance
     * @param days
     * @return
     */
    public static Date timeAfterDays(Date instance, int days) {
        Calendar calendar = Calendar.getInstance();

        calendar.setTimeInMillis(instance.getTime());

        Calendar clone = (Calendar) calendar.clone();

        clone.set(Calendar.HOUR,0);

        clone.set(Calendar.MINUTE,0);

        clone.set(Calendar.SECOND,0);

        // 加三天
        clone.add(Calendar.DAY_OF_MONTH, days - 1);

        clone.add(Calendar.HOUR, 23);

        clone.add(Calendar.MINUTE, 59);

        clone.add(Calendar.SECOND, 59);

        return new Date(clone.getTimeInMillis());
    }
}
